Address of array vs. address of array[0] - C language
        Posted  
        
            by user324994
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user324994
        
        
        
        Published on 2010-04-24T16:57:43Z
        Indexed on 
            2010/04/24
            17:03 UTC
        
        
        Read the original article
        Hit count: 225
        
My question is why does the address of an array differ from the address of its first position?
I'm trying to write my own malloc, but to start out I'm just allocating a chunk of memory and playing around with the addresses. My code looks roughly like this:
#define BUFF_SIZE 1024
static char *mallocbuff;
int main(){
     mallocbuff = malloc(BUFF_SIZE);
     printf("The address of mallocbuff is %d\n", &mallocbuff);
     printf("The address of mallocbuff[0] is %d\n", &mallocbuff[0]);
}
&mallocbuff is the same address every time I run it. &mallocbuff[0] is some random address every time. I was expecting the addresses to match each other. Can anyone explain why this isn't the case?
© Stack Overflow or respective owner